home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-tasmem.adb < prev    next >
Text File  |  1994-05-19  |  4KB  |  94 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                    S Y S T E M . T A S K _ M E M O R Y                   --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.5 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1991,1992,1993, FSU, All Rights Reserved         --
  12. --                                                                          --
  13. --  GNARL is free software; you can redistribute it and/or modify it  under --
  14. --  terms  of  the  GNU  Library General Public License as published by the --
  15. --  Free Software Foundation; either version 2,  or (at  your  option)  any --
  16. --  later  version.   GNARL is distributed in the hope that it will be use- --
  17. --  ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
  18. --  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. --  eral Library Public License for more details.  You should have received --
  20. --  a  copy of the GNU Library General Public License along with GNARL; see --
  21. --  file COPYING. If not, write to the Free Software Foundation,  675  Mass --
  22. --  Ave, Cambridge, MA 02139, USA.                                          --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Task_Primitives; use System.Task_Primitives;
  27.  
  28. package body System.Task_Memory is
  29.  
  30.    --  malloc() and free() are not currently thread-safe, though they should
  31.    --  be. In the meantime, these protected versions are provided.
  32.  
  33.    Memory_Mutex : Lock;
  34.  
  35.    --------------------
  36.    -- Low_Level_Free --
  37.    --------------------
  38.  
  39.    procedure Low_Level_Free (A : System.Address) is
  40.       procedure free (Addr : System.Address);
  41.       pragma Import (C, free, "free");
  42.  
  43.    begin
  44.       Write_Lock (Memory_Mutex);
  45.       free (A);
  46.       Unlock (Memory_Mutex);
  47.    end Low_Level_Free;
  48.  
  49.    -------------------
  50.    -- Low_Level_New --
  51.    -------------------
  52.  
  53.    function Low_Level_New
  54.      (Size : in Storage_Elements.Storage_Count)
  55.       return System.Address
  56.    is
  57.       Temp : System.Address;
  58.  
  59.       function malloc
  60.         (Size : in Storage_Elements.Storage_Count)
  61.          return System.Address;
  62.       pragma Import (C, malloc, "malloc");
  63.  
  64.    begin
  65.       Write_Lock (Memory_Mutex);
  66.       Temp := malloc (Size);
  67.       Unlock (Memory_Mutex);
  68.       return Temp;
  69.    end Low_Level_New;
  70.  
  71.    --------------------------
  72.    -- Unsafe_Low_Level_New --
  73.    --------------------------
  74.  
  75.    function Unsafe_Low_Level_New
  76.      (Size : in Storage_Elements.Storage_Count)
  77.       return System.Address
  78.    is
  79.       function malloc
  80.         (Size : in Storage_Elements.Storage_Count)
  81.          return System.Address;
  82.       pragma Import (C, malloc, "malloc");
  83.  
  84.    begin
  85.       return malloc (Size);
  86.    end Unsafe_Low_Level_New;
  87.  
  88. begin
  89.  
  90.    Initialize_Lock (Priority'Last, Memory_Mutex);
  91.    --  Initialize the lock used to synchronize low-level memory allocation.
  92.  
  93. end System.Task_Memory;
  94.